<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
    <title>熊猫格子</title>
    <link rel="stylesheet" type="text/css" href="../../../static/css/book/buy/buy_book.css"/>
    <link rel="stylesheet" type="text/css" href="../../../static/css/info_common_0304.css"/>
    <link rel="stylesheet" type="text/css" href="../../../static/css/weui.min.css"/>
</head>
<body ontouchstart>
<div class="header">
    <!--<span class="back" onclick="history.back()"><div></div></span>-->
    <!--<p class="title">买过的书</p>-->
    <div class="left">
        <div class="car_number" style="display: none">
            <img src="../../../static/img/book/headset.png"/>
        </div>
    </div>
</div>
<div class="empty_content" style="display: none">
    <div class="img">
        <img src="../../../static/img/book/buy_null.png" width="62" height="79">
        <p class="text">您还没有买过书哦，去书店逛逛吧！</p>
        <p class="btn" onclick="window.location.href='../../../index.html'">去书店</p>
    </div>
</div>
<div class="content" style="display: none">
    <img class="call_sign" src="../../../static/img/mine/call_sign.png">
    <div id="buy_list"></div>
</div>
<div class="contact">
    <div class="button">
        <div class="del1">请致电 400-116-9966 联系客服</div>
        <div class="cancel">
            <span class="can1"><button class="quxiao">取消</button></span>
            <span class="can2"><a href="tel:4001169966"><button class="shanchu go">拨打</button></a></span>
        </div>
    </div>
</div>
<div style="display: none">
    <script src="https://s22.cnzz.com/z_stat.php?id=1267301812&web_id=1267301812" language="JavaScript"></script>
</div>
</body>
<script type="text/javascript" src="../../../static/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../../../static/js/jquery.lazyload.js"></script>
<script type="text/javascript" src="../../../static/js/weui.min.js"></script>
<script type="text/javascript" src="../../../static/js/core/underscore.js"></script>
<script type="text/javascript" src="../../../static/js/core/util.js"></script>
<script type="text/javascript" src="../../../static/js/core/ocean.js"></script>
<script>
    $(".car_number,.call_sign").on("click", function () {
        $(".contact").show();
        $(".quxiao").on("click", function () {
            $(".contact").hide();
        });
    });

    $(function () {
        var params = {
            page: 1,
            limit: 10,
            type: 'buy',
            userId: ocean.getLoginUserId()
        };
        var logisticCode, shipperCode;
        ocean.get("resources/biz/api/order/list", params, function (data) {
            if (data.code == 0) {
                var content = data.data.list;
                var type = data.data.status;
                console.log(content);
                if (content.length === 0) {
                    logisticCode = data.data.expressCompany;
                    shipperCode = data.data.sendOffCode;
                    $('.car_number').css('display','block');
                    $('body').css('background-color', '#fff');
                    $(".empty_content").show();
                    $(".content").hide();
                } else {
                    $('.car_number').css('display', 'none');
                    $('body').css('background-color', '#f8f8f8');
                    $(".empty_content").hide();
                    $(".content").show();
                    var buy = _.template($('#buy_item').html());
                    $("#buy_list").append(buy({items: content}));
                }
            }
            $(".payment_btn").on("click", function () {
                var orderId = $(this).data("id");
                var type = $(this).data("status");
                var leaseOrderId = $(this).data("ef");
                ocean.get("resources/biz/userMoney/verify_money", {
                    userId: ocean.getLoginUserId(),
                    money: $(this).data("score")
                }, function (data) {
                    console.log(data);
                    if (data.code == 0) {
                        console.log(data.data);
                        console.log(leaseOrderId);
                        if (type == "CREATED") {
                            location.href = "../../order/pay.html?id=" + orderId + "&type=" + "buy";
                        } else if (type == "FromLease") {
                            orderId = leaseOrderId + "," + orderId;
                            location.href = "../../order/pay.html?id=" + orderId + "&type=" + "buy_lease";
                        }
                    } else {
                        ocean.tip("当前用户余额不足订单所需金额,请重新确认订单!");
                    }
                }, function (data) {
                    ocean.tip(data.message);
                });
            });
            $(".express_btn").on("click", function () {
                var id = $(this).data("id");
                location.href = "../../order/express.html?orderId=" + id;
            });
            $(".book_info").on("click", function () {
                location.href = "../../order/buy/buy_details.html?id=" + $(this).data("id");
            });
            if (data.data.status == "SENDED") {
                ocean.get("resources/biz/order/select_traces", {
                    orderType: "buy",
                    orderId: id,
                    logisticCode: logisticCode,
                    shipperCode: shipperCode
                }, function (data) {
                    console.log(data.data);
                    sessionStorage.setItem("WL-" + id, JSON.stringify(data.data.traces));
                    sessionStorage.setItem("orderDetail-" + id, JSON.stringify(data.data.orderDetail));
                    $("#express_state").html(data.data.traces.Traces[0].AcceptStation);
                    $("#express_time").html(data.data.traces.Traces[0].AcceptTime);
                }, function (error) {
                    ocean.tip(error);
                });
            }

        }, function (error) {
            ocean.tip(error);
        });
    });

</script>
<script id="buy_item" type="text/template">
    <@_.each(items, function (item) {@>
    <div class="info_box">
        <div class="order_info">
            <span class="order_num">订单号：<span><@=item.orderNumber@></span></span>
            <@if (item.status === "CREATED" || item.status === "FromLease") {@>
            <span class="order_state">待付款</span>
            <@} else if (item.status === "PAID") {@>
            <span class="order_state">待发货</span>
            <@}else if (item.status === "SENDED") {@>
            <span class="order_state">已发货</span>
            <@} else if (item.status === "FINISHED") {@>
            <span class="order_state">已完成</span>
            <@} else if (item.status === "EXPIRED") {@>
            <span class="order_state">已失效</span>
            <@} else if (item.status === "CANCELED") {@>
            <span class="order_state">已取消</span>
            <@} @>
        </div>
        <div class="book_info" data-id="<@=item.id@>">
            <div class="left">
                <div class="img" style="background-image: url(<@=item.bookPic.split('@')[0]@>)"></div>
            </div>
            <div class="right">
                <p class="name"><@=item.bookName.split('@')[0]@></p>
                <p class="author"><@=item.bookAuthor@></p>
                <!--<p class="grade">豆瓣评分 <@=item.score.toFixed(1)@></p>-->
                <div class="bottom_info">
                    <span class="used">二手价</span>
                    <span class="money">￥<@=item.bookPrice.split('@')[0]@></span>
                    <!--<span class="discount"><@=item.discount@>折</span></p>-->
                </div>
            </div>
        </div>
        <div class="price_info">
            共<span class="number"><@=item.totalNum@></span>本图书&nbsp;&nbsp;合计：<span data-m="<@=item.money@>"
                                                                                   class="money">￥<@=item.money@></span>
        </div>
        <@if (item.status === "CREATED" || item.status === "FromLease") {@>
        <div class="bottom_box">
            <span class="payment_btn" data-id="<@=item.id@>" data-money="<@=item.money@>" data-score="<@=item.score@>"
                  data-status="<@=item.status@>"
                  data-ef="<@=item.extendedField@>">去付款</span>
        </div>
        <@}@>
        <@if (item.status === "SENDED" || item.status === "FINISHED") {@>
        <div class="bottom_box"><span class="express_btn" data-id="<@=item.id@>">查看物流</span></div>
        <@}@>
    </div>
    <@ }); @>
</script>
</html>